//
//  MathEx.swift
//  Risac
//
//  Created by remy on 2020/5/7.
//  Copyright © 2020 com.Risac. All rights reserved.
//

extension Double {
    var cleanZero: String { internalCleanZero(self) }
}

extension Float {
    var cleanZero: String { internalCleanZero(self) }
}

private func internalCleanZero<T>(_ value: T) -> String {
    let str = "\(value)"
    let max = str.components(separatedBy: ".").last!.count
    let formatter = NumberFormatter()
    formatter.minimumFractionDigits = 0
    formatter.maximumFractionDigits = max
    formatter.numberStyle = .decimal
    if let value = value as? NSNumber {
        return formatter.string(from: value) ?? str
    }
    return str
}
